package com.toutoushidao.ssm.util;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by ThinkPad on 2016/10/24.
 */
public class Mapper {
    public static <T> Map convert2Map(T ... beans) {
        ObjectMapper mapper = new ObjectMapper();
        Map all = new HashMap();
        for (T bean : beans) {
            Map map = mapper.convertValue(bean, Map.class);

            //删除NULL
            Iterator iterator = map.entrySet().iterator();
            while(iterator.hasNext()) {
                Map.Entry entry = (Map.Entry)iterator.next();
                if(entry.getValue() == null) {
                    iterator.remove();
                }
            }

            all.putAll(map);
        }

        return all;
    }
}
